package com.example.hystrixdemo.service;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.contrib.javanica.command.HystrixCommandFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * @Package: com.example.hystrixdemo.service
 * @ClassName: AccountCommand
 * @Author: Think
 * @CreateTime: 2021/7/13 8:56
 * @Description:
 */
public class AccountCommand extends HystrixCommand<String> {

    private String name;

    public AccountCommand(String name) {
        super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"));
        this.name = name;
    }

    @Override
    protected String run() throws Exception {
        if(ObjectUtils.isEmpty(name) || !"zhangxun".equals(name)){
            throw new Exception("Account is illegal!");
        }
        return "zhangxun login success!";
    }

    @Override
    protected String getFallback() {
        return "please check your account name!";
    }
}
